package com.citcc.business.service;

import com.citcc.business.bean.AppVersion;
import com.citcc.business.mapper.AppVersionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppVersionService {

    private final AppVersionMapper appVersionMapper;

    @Autowired
    public AppVersionService(AppVersionMapper appVersionMapper){
        this.appVersionMapper=appVersionMapper;
    }

    public List<AppVersion> queryAll(AppVersion appVersion){
        return appVersionMapper.queryAll(appVersion);
    }

    public AppVersion selectAppVersion(String version,int type){
        AppVersion appVersion=appVersionMapper.selectList();
        if(appVersion!=null){
            if(1==type){
                int result=appVersion.getAndroidVersion().compareTo(version);
                if(result>=1){
                    return appVersion;
                }
            }else if(2==type){
                if(appVersion.getIosVersion().compareTo(version)>=1){
                    return appVersion;
                }
            }
        }
        return null;
    }

    public int queryExist(){
        return appVersionMapper.queryExist();
    }

    public int insert(AppVersion record){
        return appVersionMapper.insertSelective(record);
    }

    public AppVersion getAppVersion(String id){
        return appVersionMapper.selectByPrimaryKey(id);
    }

    public int update(AppVersion appVersion){
        return appVersionMapper.updateByPrimaryKeySelective(appVersion);
    }

    public  int delete(String id){
        return appVersionMapper.delete(id);
    }

}
